﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.PatientCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.PatientHandler
{
    /// <summary>
    /// 获取就诊人
    /// </summary>
    public class GetNoPatientHandler : IRequestHandler<GetNoPatientCommand, APIResult<List<Patient>>>
    {
        private readonly IBaseRepository<Patient> baseRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="baseRepository">仓储</param>
        public GetNoPatientHandler(IBaseRepository<Patient> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Patient>>> Handle(GetNoPatientCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Patient>> result = new APIResult<List<Patient>>();
            try
            {
                var list = baseRepository.GetAll().Where(x => x.PatientNo == request.PatientNo);
                result.Code = APIEnum.Mvc;
                result.Msg = "查询成功";
              
                result.Data = list.ToList();
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
